﻿using System.Linq.Expressions;

namespace MyRabbit.Repositories
{
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 单个添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<T> InsertAsync(T entity);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> InsertManyAsync(IEnumerable<T> entities);
        /// <summary>
        /// 单个删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeleteAsync(T entity);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> DeleteManyAsync(IEnumerable<T> entities);
        /// <summary>
        /// 单个修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateAsync(T entity);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        Task<int> UpdateManyAsync(IEnumerable<T> entities);
        /// <summary>
        /// 根据 ID 获取单个实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<T> GetByIdAsync(int id);
        /// <summary>
        /// 根据条件表达式获取单个实体
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        Task<T> GetByConditionAsync(Expression<Func<T, bool>> condition);
        /// <summary>
        /// 根据条件表达式获取多个实体
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        Task<List<T>> GetManyByConditionAsync(Expression<Func<T, bool>> condition);
        /// <summary>
        /// 获取全部实体
        /// </summary>
        /// <returns></returns>
        Task<List<T>> GetAllAsync();

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        Task<bool> ExistsAsync(Expression<Func<T, bool>> condition);

        /// <summary>
        /// 根据条件表达式获取多个实体并排序
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <param name="Dol"></param>
        /// <returns></returns>
        Task<List<T>> GetManyByConditionAsync<TKey>(Expression<Func<T, bool>> condition, Expression<Func<T, TKey>> orderby, bool Dol);
    }
}